#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        if (nums.size() <= 2) return nums.size();

        int i = 2;
        for (int j = 2; j < nums.size();) {
            if (nums[j] == nums[i - 2]) {
                ++j;
            }
            else {
                nums[i] = nums[j];
                ++i;
                ++j;
            }
        }

        return i;
    }
};

int main()
{
    vector<int> nums = { 1, 1, 1, 2, 2, 3 };
    cout << Solution().removeDuplicates(nums);
	return 0;
}